export function formatGetUri(obj) {
  const params = []
  Object.keys(obj).forEach((key) => {
    let value = obj[key]
    if (typeof value !== 'undefined' || value !== null) {
      params.push([key, encodeURIComponent(value)].join('='))
    }
  })
  return '?' + params.join('&')
}


export function createPromiseWithAbort(fetchPromise) { // 创建一个可终止的 Promise 对象
    let abort = null
    const abortPromise = new Promise((resolve, reject) => {
        abort = () => reject('abort')
    })
    let promiseWithAbort = Promise.race([fetchPromise, abortPromise])
    promiseWithAbort.abort = abort
    return promiseWithAbort
}

export function abortPromise(promiseWithAbort) { // 终止未完成的 Promise 对象 promiseWithAbort
    if (promiseWithAbort != null && promiseWithAbort.abort) {
        promiseWithAbort.abort()
    }
}